#include <bits/stdc++.h>
using namespace std;
#define dbg(x...)                             \
    {                                         \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    }
void err()
{
    cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
    cout << a << ' ';
    err(x...);
}

typedef long long LL;

unordered_map<LL, LL> mp;
LL dp(LL x)
{
    if (x == 1)
        return 1;
    if (mp.find(x) != mp.end())
        return mp[x];
    else
        return mp[x] = 2LL * dp(x / 2) + 1;
}

int main(int argc, char const *argv[])
{
    LL h;
    cin >> h;
    cout << dp(h) << endl;
    return 0;
}